<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/08/20
 * Time: 06:01
 */

namespace HiCommon\Model;

class Collect extends Base
{
    
    protected $table = 'user_collect';
    
    protected $guarded = [];
    
    //public $timestamps = false;
    
    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];
    
  /**
     * 获取状态对应的名称
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getStateAttribute($value)
    {
        switch ($value)
        {
            case 0:
                $res = ['id'=>0,'name'=>'草稿'];
                break;
            case 1:
                $res = ['id'=>1,'name'=>'待审核'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'通过'];
                break;
            case 3:
                $res = ['id'=>3,'name'=>'拒绝'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }
    
        /**
         * 获取图片可用链接
         *
         * @return array
         * @author wumengmeng <wu_mengmeng@foxmail.com>
         */
        public function getImgUrlAttribute($value)
        {
            $arr_data = [
              'src'=>$value,
              'full_src'=>oss_full_url($value),
            ];
            return $arr_data;
        }
        
        /**
         * 扩展信息
         *
         * @return array
         * @author wumengmeng <wu_mengmeng@foxmail.com>
         */
        public function getExtendAttribute()
        {
            $s_created_at = $this->created_at;
            $arr_data = [
              'created_at'=>ymd_friendly_date($s_created_at),
            ];

            return $arr_data;
        }

        
        /**
         *  关联商品信息
         *  hinq 2019 09 05
         *
         **/
        public function GoodsInfo(){
            return $this->belongsTo(Goods::class,'x_id','id')->select(['price','id','title','name','pic_url','integral','type','repairstore_id']);
        }

        /**
         *  关联维修店商品信息
         *  hinq 2019 09 05
         *
         **/
        public function RepairstoreGoods(){
            return $this->belongsTo(RepairstoreGoods::class,'x_id','id')->select(['id','name','price','repairstore_id']);
        }
        public function RepairstoreGoodsImg(){
            return $this->belongsTo(RepairstoreGoodsImg::class,'x_id','id')->select(['id','picurl']);
        }

        /**
         *  关联维修店商品信息
         *  hinq 2019 09 05
         *
         **/
        public function Discover(){
            return $this->belongsTo(Discover::class,'x_id')->select(['id','title','img','author_id','look_num']);
        }


        /**
         *  关联商品信息
         *  hinq 2020 4 25
         *
         **/
        public function shop(){
            return $this->belongsTo(Shop::class,'x_id');
        }
}